package cn.hdu.community.service.serviceImpl;

import cn.hdu.community.entity.Article;
import cn.hdu.community.mapper.ArticleMapper;
import cn.hdu.community.service.ArticleService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zhangxin
 * @since 2022-04-08
 */
@Service
public class ArticleServiceImpl extends ServiceImpl<ArticleMapper, Article> implements ArticleService {
    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public Article insertArticle(Integer articleAuthorId, Article newArticle) {
        Article article = new Article();
        LocalDateTime articleReleaseTime = LocalDateTime.now();
        article.setArticleTitle(newArticle.getArticleTitle());
        article.setArticleAuthorId(articleAuthorId);
        article.setArticleDetails(newArticle.getArticleDetails());
        article.setArticleCategory(newArticle.getArticleCategory());
        article.setArticleState(newArticle.getArticleState());
        article.setArticleAllowComment(newArticle.getArticleAllowComment());
        article.setArticleReleaseTime(articleReleaseTime);
        articleMapper.insert(article);
        return articleMapper.selectById(article.getArticleId());
    }

    @Override
    public List<Article> getAllArticleByAuthorId(Integer articleAuthorId) {
        return articleMapper.getAllArticleByAuthorId(articleAuthorId);
    }
}
